﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace PizzaLunch
{
    public class TweetList : ObservableCollection<TweetItem>
    {
    }

    public class TweetItem : INotifyPropertyChanged
    {
        #region INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
        #endregion

        public enum TweetItemStatus
        {
            NOT_READ,
            READ,
            RETEETED,
        }
        public enum TweetItemType
        {
            ORIGIN,
            SOURCE,
            COMMENT,
            RETWEET,
        }

        private TweetAccount _account;
        public TweetAccount Account
        { get{return _account;}}

        private string _innerXML;
        public string InnerXML
        { get { return _innerXML; } }

        public string ID
        { get; set; }

        public UserInfo Author { get; set; }
        /*public string Author
        { get; set; }

        public string AuthorID
        { get; set; }*/

        public string Content
        { get; set; }

        public DateTime DateUpdate
        { get; set; }

        public TweetItemStatus Status
        { get; set; }

        public string Thumbnail { get; set; }
        public string Image { get; set; }
        public bool HasImage { get; set; }
        public bool HasOrigin { get; set; }
        public bool IsSelf { get; set; }

        public TweetItemType Type { get; set; }

        public TweetItem SourceItem { get; set; }
        public TweetList Comments { get; set; }
        public long LastCommentTimeStamp { get; set; }
        public TweetItem LastComment { get; set; }

        public TweetItem( TweetAccount tac, string cs )
        {
            _account = tac;
            _innerXML = cs;
            Comments = new TweetList();
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
                return false;

            TweetItem ti = obj as TweetItem;
            if ((System.Object)ti == null)
                return false;

            if (ti.ID == ID && ti.Account.Equals(Account))
                return true;
            return false;
        }

        public void GetComments()
        {
            Account.GetComments(this);
        }

        public bool Comment(string Content)
        {
            return Account.Comment(this, Content);
        }

        public bool Retweet(string Content)
        {
            return Account.Retweet(this, Content);
        }

        public bool Delete()
        {
            return Account.Delete(this);
        }

        public string GetUrl()
        {
            return Account.Source.GetItemUrl(this);
        }
    }
}
